<?php
$relPath="./../../pinc/";
include_once($relPath.'site_vars.php');
require_once $relPath."dpinit.php";
include_once($relPath.'dp_main.inc');
include_once($relPath.'theme.inc');
include_once($relPath.'iso_639_list.inc');
include_once($relPath.'metarefresh.inc');

$func = Arg("func");
$lang = Arg("lang");
$location = Arg('location');

theme_header(_("Translation Center"));

if(!$User->IsSiteTranslator()) 
{
    echo _("You can not add a new language.");
    theme_footer();
    exit();
}

if (empty($lang) && $func == "newlang") 
{
    $dir = opendir($dyn_locales_dir);
    $i = 0;
    echo "
    <table>
        <ul>\n";

    while ( $file = readdir($dir)) 
    {
        switch($file)
        {
            case ".":
            case "..":
            case "CVS":
            case "translators":
            case "en_CA":
            case "messages.pot":
                break;
            default:
                foreach ($iso_639 as $short_lang => $full_lang) 
                {
                    if (!in_array($short_lang, $existing_lang)) 
                    {
                        echo "
        <tr><td>
            <li>$full_lang</li>
        </td>
        <td>[ <a href='new_lang.php?func=create_newlang&lang=" . $short_lang . "'>" . _("Create Translation File") . "</a> ]
        </td></tr>\n";
                    }
                }
                    $existing_lang[$i] = $file;
                $i++;
        }
    }

    echo "
        </ul>
    </table>\n";
}

if (!empty($lang) && $func == "create_newlang") 
{
    mkdir("$dyn_locales_dir/$lang", 0755);
    mkdir("$dyn_locales_dir/$lang/LC_MESSAGES/", 0755);
    chdir($code_dir);
    exec("$xgettext_executable `find -name \"*.php\" -o -name \"*.inc\"` -p $dyn_locales_dir/$lang/LC_MESSAGES/ --keyword=_ -C");
    chdir("$dyn_locales_dir/$lang/LC_MESSAGES/");
    exec("msgfmt messages.po -o messages.mo");

    do_metarefresh(0, "index.php?func=translate&lang=$lang", "", "");
}

theme_footer();

// vim: sw=4 ts=4 expandtab
